using TelliTwitter.Lib;
using System.Text;


namespace TelliTwitter
{
    public class ItemTemplate
    {
        private void Init()
        {
            Utils utils = new Utils();


            templateText = new StringBuilder(utils.GetResourceString("TelliTwitter.html.ItemTemplate.html"));
            templateText.Replace("{ItemContainerCssClass}", "{0}");
            templateText.Replace("{ProfileImgUrl}", "{1}");
            templateText.Replace("{UserName}", "{2}");
            templateText.Replace("{ScreenName}", "{3}");
            templateText.Replace("{Text}", "{4}");
        }

        /// <summary>
        /// holds the template text template
        /// </summary>
        private StringBuilder templateText;

        public string BuildItem(Status status, string tlitemClass)
        {
            // Build the output
            return string.Format(templateText.ToString(),
                                 tlitemClass,
                                 status.User.ProfileImageUrl,
                                 status.User.Name,
                                 status.User.ScreenName,
                                 StatusFormatter.Format(status.Text)
                );
        }

        #region Singleton Implementation

        private ItemTemplate()
        {
            Init();
        }

        public static ItemTemplate Instance
        {
            get { return creator.itemTemplate; }
        }

        private class creator
        {
            internal static readonly ItemTemplate itemTemplate = new ItemTemplate();
        }

        #endregion
    }
}
